package com.tarry.thread;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.Queue;

@Slf4j
@AllArgsConstructor
public class Consumer implements Runnable{

    private Queue<String> bags;

    private int maxSize;

    @Override
    public void run() {
        while (true) {
            synchronized (this.bags) {
                if (this.bags.isEmpty()) {
                    log.warn("the bags is empty");
                    try {
                        this.bags.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                try {
                    Thread.sleep(1000);
                    String bag = this.bags.remove();
                    log.info("consumer get bag is {}",bag);
                    this.bags.notify();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
